package leetcode.greedy;

import java.util.PriorityQueue;

public class lessMoney {
    public static int process(int[] arr){
        PriorityQueue<Integer> pQ = new PriorityQueue<>();

        for (int i = 0; i < arr.length; i++) {
            pQ.add(arr[i]);
        }
        int sum = 0;
        int cur = 0;
        while (pQ.size()>1){
            cur = pQ.poll() +pQ.poll();
            sum += cur;
            pQ.add(cur);
        }
        return sum;
    }
}
